﻿using System.Collections.Generic;
using IdentityServer4.Models;

namespace IdentityServer4.IdServer
{
    public class Config
    {
        /// <summary>
        /// 返回API资源列表
        /// </summary>
        /// <returns></returns>
        public static IEnumerable<ApiResource> GetApiResources()
        {
            List<ApiResource> resources = new List<ApiResource>();

            //ApiResource第一个参数是应用的名字，第二个参数是描述
            resources.Add(new ApiResource("MsgAPI", "消息服务API"));
            resources.Add(new ApiResource("ProductAPI", "产品服务API"));
            return resources;
        }

        /// <summary>
        /// 返回API客户端列表
        /// </summary>
        /// <returns></returns>
        public static IEnumerable<Client> GetClients()
        {
            List<Client> clients = new List<Client>();

            clients.Add(new Client()
            {
                ClientId = "HYD-PC-101",
                AllowedGrantTypes = GrantTypes.ClientCredentials,
                ClientSecrets = {
                    new Secret ("HYD-PC-101:123654".Sha256())
                },
                AllowedScopes = { "MsgAPI", "ProductAPI" }

            });

            clients.Add(new Client()
            {
                ClientId = "HYD-ANDROID-101",
                AllowedGrantTypes = GrantTypes.ClientCredentials,
                ClientSecrets = {
                    new Secret ("HYD-ANDROID-101:123654".Sha256())
                },
                AllowedScopes = { "MsgAPI" }

            });

            clients.Add(new Client()
            {
                ClientId = "HYD-IOS-101",
                AllowedGrantTypes = GrantTypes.ClientCredentials,
                ClientSecrets = {
                    new Secret ("HYD-IOS-101:123654".Sha256())
                },
                AllowedScopes = { "ProductAPI" }

            });

            return clients;
        }
    }
}
